%{// -*- mode: c -*-
/*****************************************************************************/
/*  LibreDWG - free implementation of the DWG file format                    */
/*                                                                           */
/*  Copyright (C) 2020 Free Software Foundation, Inc.                        */
/*                                                                           */
/*  This library is free software, licensed under the terms of the GNU       */
/*  General Public License as published by the Free Software Foundation,     */
/*  either version 3 of the License, or (at your option) any later version.  */
/*  You should have received a copy of the GNU General Public License        */
/*  along with this program.  If not, see <http://www.gnu.org/licenses/>.    */
/*****************************************************************************/

/*
 * dxfclasses.c: create classes, lookup the initial class values from its DXF name.
 *               generated via gperf from dxfclasses.in
 *
 * written Reini Urban
 */

#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdbool.h>
#include <limits.h>
#include "config.h"
#include "dwg.h"
#include "common.h"
// other imports
int dwg_add_class (Dwg_Data *restrict dwg, const char *const restrict dxfname,
                   const char *const restrict cppname, const char *const restrict appname,
                   const bool is_entity);
// export
EXPORT int dwg_require_class (Dwg_Data *restrict dwg,
                              const char *const restrict dxfname, const size_t len);

// v3.1 changed len type from unsigned int to size_t (gperf d519d1a821511eaa22eae6d9019a548aea21e6)
static const struct Dwg_DXFClass *in_word_set (const char *str, size_t len);

enum apptypes
{
  ODBXCLASS,
  ODBX_OR_A2000CLASS,
  A2000CLASS,
  SCENEOECLASS,
  ISMCLASS,
  EXPRESSCLASS,
  POINTCLOUDCLASS,
  DGNLSCLASS,
  AEC60CLASS,
  SPECIALCLASS,
};
#define ODBX ODBXCLASS
#define ISM ISMCLASS
#define SCENEOE SCENEOECLASS
#define EXPRESS EXPRESSCLASS
#define POINTCLOUD POINTCLOUDCLASS
#define DGNLS DGNLSCLASS
#define AEC60 AEC60CLASS
#define SPECIAL SPECIALCLASS
//%null-strings

%}
%7bit
%language=ANSI-C
%struct-type
%readonly-tables
%pic

struct Dwg_DXFClass {int name; const char *const cppname; unsigned apptype:4; unsigned isent:1;};

GCC46_DIAG_IGNORE(-Wmissing-field-initializers)

%%
# Entities
LWPOLYLINE,	"AcDbPolyline",		ODBX,	1
HATCH,		"AcDbHatch",		ODBX,	1
OLE2FRAME,	"AcDbOle2Frame",	ODBX,	1
ARC_DIMENSION,	"AcDbArcDimension",	ODBX,	1
MULTILEADER,	"AcDbMLeader",		ODBX,	1
ACAD_TABLE,	"AcDbTable",		ODBX,	1
PDFUNDERLAY, 	"AcDbPdfReference",   	ODBX,	1
DGNUNDERLAY, 	"AcDbDgnReference",   	ODBX,	1
DWFUNDERLAY, 	"AcDbDwfReference",   	ODBX,	1
#
ACDBDICTIONARYWDFLT,		"AcDbDictionaryWithDefault",	ODBX_OR_A2000CLASS,	0
ACDBPLACEHOLDER,		"AcDbPlaceHolder",		ODBX_OR_A2000CLASS,	0
ACAD_PROXY_ENTITY_WRAPPER,	"AcDbProxyEntityWrapper",	ODBX_OR_A2000CLASS,	0
ACAD_PROXY_OBJECT_WRAPPER,	"AcDbProxyObjectWrapper",	ODBX_OR_A2000CLASS,	0
#
DICTIONARYVAR,	"AcDbDictionaryVar",	A2000CLASS,	0
LAYOUT,		"AcDbLayout",		A2000CLASS,	0
SORTENTSTABLE,	"AcDbSortentsTable",	A2000CLASS,	0
#
VBA_PROJECT,	"AcDbVbaProject",	ODBX,	0
XRECORD,	"AcDbXrecord",		ODBX,	0
LAYER_INDEX,	"AcDbLayerIndex",	ODBX,	0
SPATIAL_INDEX,	"AcDbSpatialIndex",	ODBX,	0
SPATIAL_FILTER,	"AcDbSpatialFilter",	ODBX,	0
IDBUFFER,	"AcDbIdBuffer",		ODBX,	0
VISUALSTYLE,	"AcDbVisualStyle",	ODBX,	0
TABLESTYLE,	"AcDbTableStyle",	ODBX,	0
TABLECONTENT,	"AcDbTableContent",	ODBX,	0
TABLEGEOMETRY,	"AcDbTableGeometry",	ODBX,	0
CELLSTYLEMAP,	"AcDbCellStyleMap",	ODBX,	0
DATATABLE,	"AcDbDataTable",	ODBX,	0
SCALE,		"AcDbScale",		ODBX,	0
DGNDEFINITION, 	"AcDbDgnDefinition",   	ODBX,	0
DWFDEFINITION, 	"AcDbDwfDefinition",   	ODBX,	0
PDFDEFINITION, 	"AcDbPdfDefinition",   	ODBX,	0
#
IMAGE,		"AcDbRasterImage",	ISM,	1
IMAGEDEF,	"AcDbRasterImageDef",	ISM,	0
IMAGEDEF_REACTOR,"AcDbRasterImageDefReactor",	ISM,	0
RASTERVARIABLES,"AcDbRasterVariables",	ISM,	0
#
LIGHT,		"AcDbLight",		SCENEOE, 1
LIGHTLIST,	"AcDbLightList",	SCENEOE, 0
SUN, 		"AcDbSun",		SCENEOE, 0
SUNSTUDY,	"AcDbSunStudy",		SCENEOE, 0
#
DIMASSOC, 	"AcDbDimAssoc",		SPECIAL, 0
WIPEOUT,	"AcDbWipeout", 		SPECIAL, 1
WIPEOUTVARIABLES,"AcDbWipeoutVariables",	ODBX,	0
RTEXT, 		"AcDbRText", 		EXPRESS, 1
ARCALIGNEDTEXT, "AcDbArcAlignedText",	EXPRESS, 1
MLEADERSTYLE,	"AcDbMLeaderStyle",	SPECIAL, 0
#
MATERIAL,		"AcDbMaterial",		ODBX,	0
PLOTSETTINGS,		"AcDbPlotSettings",	ODBX,	0
ACDBSECTIONVIEWSTYLE,	"AcDbSectionViewStyle",	ODBX,	0
ACDBDETAILVIEWSTYLE,	"AcDbDetailViewStyle",	ODBX,	0
POSITIONMARKER,		"AcDbGeoPositionMarker",ODBX,	0
ACAD_EVALUATION_GRAPH,	"AcDbEvalGraph",	ODBX,	0
#
SURFACE,		"AcDbSurface",		ODBX,	1
EXTRUDEDSURFACE,	"AcDbExtrudedSurface",	ODBX,	1
LOFTEDSURFACE,		"AcDbLoftedSurface",	ODBX,	1
NURBSURFACE,		"AcDbNurbSurface",	ODBX,	1
PLANESURFACE,		"AcDbPlaneSurface",	ODBX,	1
REVOLVEDSURFACE,	"AcDbRevolvedSurface",	ODBX,	1
SWEPTSURFACE,		"AcDbSweptSurface",	ODBX,	1
#
ACSH_BOOLEAN_CLASS,	"AcDbShBoolean",	ODBX,	0
ACSH_BOX_CLASS,		"AcDbShBox",		ODBX,	0
ACSH_BREP_CLASS,	"AcDbShBrep",		ODBX,	0
ACSH_CHAMFER_CLASS,	"AcDbShChamfer",	ODBX,	0
ACSH_CONE_CLASS,	"AcDbShCone",		ODBX,	0
ACSH_CYLINDER_CLASS,	"AcDbShCylinder",	ODBX,	0
ACSH_EXTRUSION_CLASS,	"AcDbShExtrusion",	ODBX,	0
ACSH_FILLET_CLASS,	"AcDbShFillet",		ODBX,	0
ACSH_HISTORY_CLASS,	"AcDbShHistory",	ODBX,	0
ACSH_LOFT_CLASS,	"AcDbShLoft",		ODBX,	0
ACSH_PYRAMID_CLASS,	"AcDbShPyramid",	ODBX,	0
ACSH_REVOLVE_CLASS,	"AcDbShRevolve",	ODBX,	0
ACSH_SPHERE_CLASS,	"AcDbShSphere",		ODBX,	0
ACSH_SWEEP_CLASS,	"AcDbShSweep",		ODBX,	0
ACSH_TORUS_CLASS,	"AcDbShTorus",		ODBX,	0
ACSH_WEDGE_CLASS,	"AcDbShWedge",		ODBX,	0
#
ACDBASSOCPERSSUBENTMANAGER,	"AcDbAssocPersSubentManager",	ODBX,	0
ACDBPERSSUBENTMANAGER, 		"AcDbPersSubentManager",	ODBX, 0
ACDBASSOCNETWORK,		"AcDbAssocNetwork",		ODBX,	0
ACDBASSOCACTION,		"AcDbAssocAction",		ODBX,	0
ACDBASSOCALIGNEDDIMACTIONBODY,	"AcDbAssocAlignedDimActionBody",	ODBX,	0
ACDBASSOCOSNAPPOINTREFACTIONPARAM,"AcDbAssocOsnapPointRefActionParam",	ODBX,	0
ACDBASSOCVERTEXACTIONPARAM,	"AcDbAssocVertexActionParam",	ODBX,	0
ACDBASSOCGEOMDEPENDENCY,	"AcDbAssocGeomDependency",	ODBX,	0
ACDBASSOCDEPENDENCY,		"AcDbAssocDependency",		ODBX,	0
ACDBASSOCDIMDEPENDENCYBODY,	"AcDbAssocDimDependencyBody",	ODBX,	0
ACDBBLOCKPARAMDEPENDENCYBODY,	"AcDbBlockParameterDependencyBody",	ODBX,	0
#
ACDBASSOC3POINTANGULARDIMACTIONBODY,"AcDbAssoc3PointAngularDimActionBody",	ODBX,	0
ACDBASSOCALIGNEDIMACTIONBODY,	"AcDbAssocAlignedDimActionBody",	ODBX,	0
ACDBASSOCORDINATEDIMACTIONBODY,	"AcDbAssocOrdinatedDimActionBody",	ODBX,	0
ACDBASSOCROTATEDDIMACTIONBODY,	"AcDbAssocRotatedDimActionBody",	ODBX,	0
#
ACDBASSOCARRAYMODIFYACTIONBODY,	"AcDbAssocArrayModifyActionBody",	ODBX,	0
ACDBASSOCARRAYACTIONBODY,	"AcDbAssocArrayActionBody",		ODBX,	0
ACDBASSOCEDGECHAMFERACTIONBODY,	"AcDbAssocEdgeChamferActionBody",	ODBX,	0
ACDBASSOCEDGEFILLETACTIONBODY,	"AcDbAssocEdgeFilletActionBody",	ODBX,	0
ACDBASSOCMLEADERACTIONBODY,	"AcDbAssocMLeaderActionBody",		ODBX,	0
CONTEXTDATAMANAGER,		"AcDbContextDataManager",		ODBX,	0
#
ACDBASSOCBLENDSURFACEACTIONBODY,	"AcDbAssocBlendSurfaceActionBody",	ODBX,	0
ACDBASSOCEXTENDSURFACEACTIONBODY,	"AcDbAssocExtendSurfaceActionBody",	ODBX,	0
ACDBASSOCEXTRUDEDSURFACEACTIONBODY,	"AcDbAssocExtrudedSurfaceActionBody",	ODBX,	0
ACDBASSOCFILLETSURFACEACTIONBODY,	"AcDbAssocFilletSurfaceActionBody",	ODBX,	0
ACDBASSOCLOFTEDSURFACEACTIONBODY,	"AcDbAssocLoftedSurfaceActionBody",	ODBX,	0
ACDBASSOCNETWORKSURFACEACTIONBODY,	"AcDbAssocNetworkSurfaceActionBody",	ODBX,	0
ACDBASSOCOFFSETSURFACEACTIONBODY,	"AcDbAssocOffsetSurfaceActionBody",	ODBX,	0
ACDBASSOCPLANESURFACEACTIONBODY,	"AcDbAssocPlaneSurfaceActionBody",	ODBX,	0
ACDBASSOCPATCHSURFACEACTIONBODY,	"AcDbAssocPatchSurfaceActionBody",	ODBX,	0
ACDBASSOCRESTOREENTITYSTATEACTIONBODY,	"AcDbAssocRestoreEntityStateActionBody",ODBX,	0
ACDBASSOCREVOLVEDSURFACEACTIONBODY,	"AcDbAssocRevolvedSurfaceActionBody",	ODBX,	0
ACDBASSOCSWEPTSURFACEACTIONBODY,	"AcDbAssocSweptSurfaceActionBody",	ODBX,	0
ACDBASSOCTRIMSURFACEACTIONBODY,		"AcDbAssocTrimSurfaceActionBody",	ODBX,	0
#
ACDBASSOCACTIONPARAM,			"AcDbAssocActionParam",		ODBX,	0
ACDBASSOCASMBODYACTIONPARAM,		"AcDbAssocAsmbodyActionParam",	ODBX,	0
ACDBASSOCCOMPOUNDACTIONPARAM,		"AcDbAssocCompoundActionParam",	ODBX,	0
ACDBASSOCEDGEACTIONPARAM,		"AcDbAssocEdgeActionParam",	ODBX,	0
ACDBASSOCFACEACTIONPARAM,		"AcDbAssocFaceActionParam",	ODBX,	0
ACDBASSOCPATHACTIONPARAM,		"AcDbAssocPathActionParam",	ODBX,	0
ACDBASSOCOBJECTACTIONPARAM,		"AcDbAssocObjectActionParam",	ODBX,	0
ACDBASSOCPOINTREFACTIONPARAM,		"AcDbAssocPointRefActionParam",	ODBX,	0
#
ACDBASSOCARRAYMODIFYPARAMETERS,		"AcDbAssocArrayModifyParameters",	ODBX,	0
ACDBASSOCARRAYPATHPARAMETERS,		"AcDbAssocArrayPathParameters",		ODBX,	0
ACDBASSOCARRAYPOLARPARAMETERS,		"AcDbAssocArrayPolarParameters",	ODBX,	0
ACDBASSOCARRAYRECTANGULARPARAMETERS,	"AcDbAssocArrayRectangularParameters",	ODBX,	0
#
ALIGNMENTPARAMETERENTITY,		"AcDbBlockAlignmentParameterEntity",	ODBX,	1
BASEPOINTPARAMETERENTITY,		"AcDbBlockBasepointParameterEntity",	ODBX,	1
FLIPPARAMETERENTITY,			"AcDbBlockFlipParameterEntity",		ODBX,	1
LINEARPARAMETERENTITY,			"AcDbBlockLinearParameterEntity",      	ODBX,	1
POINTPARAMETERENTITY,			"AcDbBlockPointParameterEntity",      	ODBX,	1
ROTATIONPARAMETERENTITY,		"AcDbBlockRotationParameterEntity",     ODBX,	1
POLARGRIPENTITY,			"AcDbBlockPolarGripEntity",		ODBX,	1
XYPARAMETERENTITY,			"AcDbBlockXYParameterEntity",		ODBX,	1
# more Dynblocks
ACDB_BLOCKREPRESENTATION_DATA,		"AcDbBlockRepresentationData",     	ODBX,	0
BLOCKARRAYACTION,			"AcDbBlockArrayAction",     		ODBX,	0
BLOCKANGULARCONSTRAINTPARAMETER,	"AcDbBlockAngularConstraintParameter",  ODBX,	0
BLOCKDIAMETRICCONSTRAINTPARAMETER,	"AcDbBlockDiametricConstraintParameter",ODBX,	0
BLOCKRADIALCONSTRAINTPARAMETER,		"AcDbBlockRadialConstraintParameter",	ODBX,	0
BLOCKALIGNEDCONSTRAINTPARAMETER,	"AcDbBlockAlignedConstraintParameter",  ODBX,	0
BLOCKLINEARCONSTRAINTPARAMETER,		"AcDbBlockLinearConstraintParameter",	ODBX,	0
BLOCKHORIZONTALCONSTRAINTPARAMETER,	"AcDbBlockHorizontalConstraintParameter",ODBX,	0
BLOCKVERTICALCONSTRAINTPARAMETER,	"AcDbBlockVerticalConstraintParameter",	ODBX,	0
BLOCKMOVEACTION,			"AcDbBlockMoveAction",			ODBX,	0
BLOCKFLIPACTION,			"AcDbBlockFlipAction",			ODBX,	0
BLOCKLOOKUPACTION,			"AcDbBlockLookupAction",		ODBX,	0
BLOCKROTATEACTION,			"AcDbBlockRotateAction",		ODBX,	0
BLOCKSCALEACTION,			"AcDbBlockScaleAction",			ODBX,	0
BLOCKPOLARSTRETCHACTION,		"AcDbBlockPolarStretchAction",	       	ODBX,	0
BLOCKSTRETCHACTION,			"AcDbBlockStretchAction",	       	ODBX,	0
BLOCKLOOKUPPARAMETER,			"AcDbBlockLookupParameter",		ODBX,	0
BLOCKPOINTPARAMETER,			"AcDbBlockPointParameter",		ODBX,	0
BLOCKROTATIONPARAMETER,			"AcDbBlockRotationParameter",		ODBX,	0
BLOCKPOLARPARAMETER,			"AcDbBlockPolarParameter",		ODBX,	0
BLOCKPOLARGRIP,				"AcDbBlockPolarGrip",			ODBX,	0
BLOCKROTATIONGRIP,			"AcDbBlockRotationGrip",		ODBX,	0
BLOCKVISIBILITYGRIP,			"AcDbBlockVisibilityGrip",		ODBX,	0
BLOCKXYGRIP,				"AcDbBlockXYGrip",			ODBX,	0
BLOCKGRIPLOCATIONCOMPONENT,		"AcDbBlockGripExpr",			ODBX,	0
BLOCKALIGNMENTGRIP,			"AcDbBlockAlignmentGrip",		ODBX,	0
BLOCKALIGNMENTPARAMETER,		"AcDbBlockAlignmentParameter",		ODBX,	0
BLOCKLINEARPARAMETER,			"AcDbBlockLinearParameter",		ODBX,	0
BLOCKBASEPOINTPARAMETER,		"AcDbBlockBasepointParameter",		ODBX,	0
BLOCKFLIPPARAMETER,			"AcDbBlockFlipParameter",		ODBX,	0
BLOCKFLIPGRIP,				"AcDbBlockFlipGrip",			ODBX,	0
BLOCKLINEARGRIP,			"AcDbBlockLinearGrip",			ODBX,	0
BLOCKLOOKUPGRIP,			"AcDbBlockLookupGrip",			ODBX,	0
BLOCKUSERPARAMETER,   			"AcDbBlockUserParameter",		ODBX,	0
BLOCKXYPARAMETER,			"AcDbBlockXYParameter",			ODBX,	0
BLOCKVISIBILITYPARAMETER,		"AcDbBlockVisibilityParameter",		ODBX,	0
BLOCKPROPERTIESTABLE,			"AcDbBlockPropertiesTable",		ODBX,	0
BLOCKPROPERTIESTABLEGRIP,   		"AcDbBlockPropertiesTableGrip",		ODBX,	0
ACDB_DYNAMICBLOCKPROXYNODE,		"AcDbDynamicBlockProxyNode",	       	ODBX,	0
ACDB_DYNAMICBLOCKPURGEPREVENTER_VERSION,"AcDbDynamicBlockPurgePreventer",      	ODBX,	0
#
ACDBCURVEPATH,   			"AcDbCurvePath",			SCENEOE,	0
ACDBMOTIONPATH,   			"AcDbMotionPath",			SCENEOE,	0
ACDBPOINTPATH,   			"AcDbPointPath",			SCENEOE,	0
MENTALRAYRENDERSETTINGS,   		"AcDbMentalRayRenderSettings",		SCENEOE,	0
RAPIDRTRENDERSETTINGS,   		"AcDbRapidRTRenderSettings",		ODBX,		0
RENDERENVIRONMENT,   			"AcDbRenderEnvironment",		SCENEOE,	0
RENDERGLOBAL,   			"AcDbRenderGlobal",			SCENEOE,	0
RENDERENTRY, 	  			"AcDbRenderEntry",			SCENEOE,	0
RAPIDRTRENDERENVIRONMENT,   		"AcDbIBLBackground",			SCENEOE,	0
SKYLIGHT_BACKGROUND,	   		"AcDbSkyBackground",			SCENEOE,	0
IMAGE_BACKGROUND,	   		"AcDbImageBackground",			SCENEOE,	0
SOLID_BACKGROUND,	   		"AcDbSolidBackground",			SCENEOE,	0
GROUND_PLANE_BACKGROUND,	   	"AcDbGroundPlaneBackground",		SCENEOE,	0
GRADIENT_BACKGROUND,	   		"AcDbGradientBackground",		SCENEOE,	0
#
ACDB_ALDIMOBJECTCONTEXTDATA_CLASS,	"AcDbAlignedDimensionObjectContextData",ODBX,	0
ACDB_ANGDIMOBJECTCONTEXTDATA_CLASS,	"AcDbAngularDimensionObjectContextData",ODBX,	0
ACDB_ANNOTSCALEOBJECTCONTEXTDATA_CLASS,	"AcDbAnnotScaleObjectContextData",	ODBX,	0
ACDB_BLKREFOBJECTCONTEXTDATA_CLASS,	"AcDbBlkrefObjectContextData",		ODBX,	0
ACDB_DMDIMOBJECTCONTEXTDATA_CLASS,	"AcDbDiametricDimensionObjectContextData",ODBX,	0
ACDB_FCFOBJECTCONTEXTDATA_CLASS,	"AcDbFcfObjectContextData",		ODBX,	0
ACDB_LEADEROBJECTCONTEXTDATA_CLASS,	"AcDbLeaderObjectContextData",		ODBX,	0
ACDB_MLEADEROBJECTCONTEXTDATA_CLASS,	"AcDbMLeaderObjectContextData",		ODBX,	0
ACDB_ORDDIMOBJECTCONTEXTDATA_CLASS,	"AcDbOrdinateDimensionObjectContextData",	ODBX,	0
ACDB_RADIMLGOBJECTCONTEXTDATA_CLASS,	"AcDbRadialDimensionLargeObjectContextData",	ODBX,	0
ACDB_RADIMOBJECTCONTEXTDATA_CLASS,	"AcDbRadialDimensionObjectContextData",	ODBX,	0
ACDB_TEXTOBJECTCONTEXTDATA_CLASS,	"AcDbTextObjectContextData",		ODBX,	0
#
ACDBPOINTCLOUD,				"AcDbPointCloud",			POINTCLOUD, 1
ACDBPOINTCLOUDEX,			"AcDbPointCloudEx",			POINTCLOUD, 1
ACDBPOINTCLOUDDEF,			"AcDbPointCloudDef",			POINTCLOUD, 0
ACDBPOINTCLOUDDEFEX,			"AcDbPointCloudDefEx",			POINTCLOUD, 0
ACDBPOINTCLOUDDEF_REACTOR,		"AcDbPointCloudDefReactor",		POINTCLOUD, 0
ACDBPOINTCLOUDDEF_REACTOR_EX,		"AcDbPointCloudDefReactorEx",		POINTCLOUD, 0
ACDBPOINTCLOUDCOLORMAP,			"AcDbPointCloudColorMap",		POINTCLOUD, 0
#
EXACXREFPANELOBJECT,			"ExAcXREFPanelObject",		SPECIAL, 0
NPOCOLLECTION,				"AcDbImpNonPersistentObjectsCollection", ODBX, 0
PARTIAL_VIEWING_FILTER,			"OdDbPartialViewingFilter",	SPECIAL, 0
PARTIAL_VIEWING_INDEX,			"OdDbPartialViewingIndex",	SPECIAL, 0
LSDEFINITION,				"AcDbLSDefinition",		DGNLS, 0
LSSTROKEPATTERNCOMPONENT,	       	"AcDbLSStrokePatternComponent",	DGNLS, 0
LSINTERNALCOMPONENT,			"AcDbLSInternalComponent",	DGNLS, 0
LSCOMPOUNDCOMPONENT,			"AcDbLSCompoundComponent",	DGNLS, 0
LSPOINTCOMPONENT,			"AcDbLSPointComponent",		DGNLS, 0
LSSYMBOLCOMPONENT,			"AcDbLSSymbolComponent",	DGNLS, 0
AEC_REFEDIT_STATUS_TRACKER,		"AecDbRefEditStatusTracker",    AEC60, 0
%%

/* Create classes on demand.
   Returns found or new klass->number id (always >=500), <0 on error.
   -1 out of memory (from dwg_add_class())
   -2 unknown class for dxfname.
   -3 invalid apptype for class. (should not happen)
*/
EXPORT int
dwg_require_class (Dwg_Data *restrict dwg, const char *const restrict dxfname, const size_t len)
{
  const struct Dwg_DXFClass* result;
  for (BITCODE_BL i = 0; i < dwg->num_classes; i++)
    {
      Dwg_Class *klass = &dwg->dwg_class[i];
      if (strEQ (klass->dxfname, dxfname))
        return klass->number;
    }

  result = in_word_set (dxfname, len);
  if (result)
    {
      switch ((enum apptypes)result->apptype)
        {
        case ODBXCLASS:
          return dwg_add_class (dwg, dxfname, result->cppname, "ObjectDBX Classes", result->isent);
        case ODBX_OR_A2000CLASS:
          return dwg_add_class (dwg, dxfname, result->cppname,
                         dwg->header.from_version <= R_2000 ? "AutoCAD 2000" : "ObjectDBX Classes",
                         result->isent);
        case A2000CLASS:
          return dwg_add_class (dwg, dxfname, result->cppname, "AutoCAD 2000", result->isent);
        case SCENEOECLASS:
          return dwg_add_class (dwg, dxfname, result->cppname, "SCENEOE", result->isent);
        case ISMCLASS:
          return dwg_add_class (dwg, dxfname, result->cppname, "ISM", result->isent);
        case POINTCLOUDCLASS:
          return dwg_add_class (dwg, dxfname, result->cppname, "AcDbPointCloudObj", result->isent); //appname?
        case DGNLSCLASS:
          return dwg_add_class (dwg, dxfname, result->cppname, "AcDgnLS", result->isent);
        case AEC60CLASS:
          return dwg_add_class (dwg, dxfname, result->cppname, "AecArchBase60|Product Desc: "
                                "Autodesk Architectural Desktop 2007", result->isent);
        case EXPRESSCLASS:
          {
            char appname[128];
            strcpy (appname, dxfname);
            strcat (appname, "|AutoCAD Express Tool");
            return dwg_add_class (dwg, dxfname, result->cppname, appname, result->isent);
          }
        case SPECIALCLASS:
          {
            char appname[128];
            if (strEQc (dxfname, "MLEADERSTYLE"))
              strcpy (appname, "ACDB_MLEADERSTYLE_CLASS");
            else if (strEQc (dxfname, "WIPEOUT"))
              strcpy (appname, "Wipeout|Product Desc:     WipeOut Dbx Application");
            else if (strEQc (dxfname, "DIMASSOC"))
              strcpy (appname, "AcDbDimAssoc|Product Desc:     AcDim ARX App For Dimension");
            else if (memBEGINc (dxfname, "PARTIAL_VIEWING_"))
              strcpy (appname, "OdDbPartialViewing|https://www.opendesign.com Teigha(R) Core Db");
            else
              {
                strcpy (appname, result->cppname);
                strcat (appname, "|Unknown ARX App");
              }
            return dwg_add_class (dwg, dxfname, result->cppname, appname, result->isent);
          }
          break;
        default:
          fprintf (stderr, "dxfclass_require: Invalid apptype %d", (int)result->apptype);
          return -3;
        }
    }
  return -2;
}

GCC46_DIAG_RESTORE

/*
 * Local variables:
 *   c-file-style: "gnu"
 * End:
 * vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
 */
